package lm.concurrency.day1;

import lm.concurrency.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: Min.Liu
 * @Description: 守护线程测试类
 * @Date: Created in 9:06 2024/6/4
 */
@Slf4j
public class DaemonThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Test2();
    }
    private static void Test2(){
        Thread t1 = new Thread(()->{
            log.info("守护线程启动");
            Sleeper.sleep(2);
            log.info("守护线程结束");
        });
        t1.setDaemon(true);
        t1.start();
        Sleeper.sleep(1);
        log.info("主线程结束");
    }

    private static void test1() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    break;
                }
            }
            log.debug("结束");
        }, "t1");
        t1.setDaemon(true);
        t1.start();

        Thread.sleep(1000);
        log.debug("结束");
    }
}
